package risk.control.project.config.mongo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;

/**
 * 全局单例，不需要释放资源，每次创建
 * mongoClient.close();
 */
@Configuration
public class MongoDbConfig {
    private static final Logger logger = LoggerFactory.getLogger(MongoDbConfig.class);

    private static final String host = "172.26.2.98";
    private static final int port = 27017;
    private static final String userName = "admin";
    private static final String password = "abc123456";


//    @Bean(name = {"MongoClient"})
//    public MongoClient mongoClient() {
//        // 配置连接池和超时设置
//        String mongoUri = "mongodb://" + userName + ":" + password + "@" + host + ":" + port + "/";
//        logger.warn("==》MongoDB初始化了{}", mongoUri);
//        ConnectionString connectionString = new ConnectionString(mongoUri);
//        MongoClientSettings settings = MongoClientSettings.builder()//
//                .applyConnectionString(connectionString)//
//                .applyToConnectionPoolSettings(builder ->//
//                        builder.maxSize(1000) // 连接池最大连接数
//                                .minSize(10) // 最小连接数
//                                .maxWaitTime(60, TimeUnit.SECONDS) // 最大等待时间
//                                .maxConnectionLifeTime(15, TimeUnit.MINUTES)) // 连接最大生命周期
//                .applyToSocketSettings(builder ->//
//                        builder.connectTimeout(60, TimeUnit.SECONDS) // 连接超时
//                                .readTimeout(60, TimeUnit.SECONDS)) // 读取超时
//                .build();
//        return MongoClients.create(settings);
//    }

}
